﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Entity;
using yunbo.Model.SSM;
using yunbo.Repositorys.SSMRepositorys;

namespace yunbo.Controllers.SSMControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        RoleRepository roleRepositorys = new RoleRepository();
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFYRole")]
        public IActionResult GetFYUser(int PageNumber, int PageSize)
        {
            FYRole role = roleRepositorys.GetFYRole(PageNumber, PageSize);
            return Ok(role);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetRole")]
        public IActionResult GetRole()
        {
            List<Role> role = roleRepositorys.GetRole();
            return Ok(role);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPost("PostRole")]
        public IActionResult PostRole(TJRole tjrole)
        {
            Role role = new Role()
            {
                role_name = tjrole.role_name,
                role_notes = tjrole.role_notes,
                role_status = 1,
                role_create_by = tjrole.role_create_by,
                role_create_time = DateTime.Now
            };
            bool rs = roleRepositorys.PostRole(role) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdateRole")]
        public IActionResult UpdateRole(XGRole xgrole)
        {
            Role role = new Role()
            {
                role_id = xgrole.role_id,
                role_name = xgrole.role_name,
                role_notes = xgrole.role_notes,
                role_update_by = xgrole.role_update_by,
                role_update_time = DateTime.Now
            };
            bool i = roleRepositorys.UpdateRole(role) > 0;
            return Ok(i);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete("DeleteRole")]
        public IActionResult DeleteRole(int id)
        {
            bool rs = roleRepositorys.DeleteRole(id) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFYMHRole")]
        public IActionResult GetFYMHRole(int PageNumber, int PageSize, int? state, string? uname)
        {
            FYRole role = roleRepositorys.GetFYMHRole(PageNumber, PageSize, state, uname);
            return Ok(role);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        [HttpPost("PostUser_Role")]
        public IActionResult PostUser_Role(string code,int id)
        {
            bool rs = roleRepositorys.PostUser_Role(code,id) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdateUser_Role")]
        public IActionResult UpdateUser_Role(string code, int id)
        {
            bool rs = roleRepositorys.UpdateUser_Role(code, id) > 0;
            return Ok(rs);
        }
        /// <summary>
        /// 查
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetUser_Role")]
        public IActionResult GetUser_Role(string code)
        {
            int rs = roleRepositorys.GetUser_Role(code);
            return Ok(rs);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdateRoleZT")]
        public IActionResult UpdateRoleZT(int id, int state)
        {
            bool rs = roleRepositorys.UpdateRoleZT(id, state) > 0;
            return Ok(rs);
        }
    }
}
